<?php
/**
 * 公共控制器
 */
class CommonController extends Controller{

	public function __Init(){
		if(!defined('__TEMPLATE__')){
			//定义模板文件目录
			define('__TEMPLATE__',__ROOT__.'/Template/'.C('INDEX_TPL_STYLE'));
		}
		$this->category();
		$this->nav();
	}
	public function dis($tpl){
		$this->display('Template/'.C('INDEX_TPL_STYLE').'/'.$tpl);
	}
	public function category(){
		 //显示分类 侧导航
    	$topCate = M('category')->where("pid = 0")->limit(14)->all();
		foreach($topCate as $k => $v){
			$topCate[$k]['first'] = M('category')->where("pid={$v['cid']}")->limit(3)->all();
			$topCate[$k]['second'] = M('category')->where("pid={$v['cid']}")->all();
			foreach($topCate[$k]['second'] as $key => $val){
				$topCate[$k]['second'][$key]['three'] = M('category')->where("pid ={$val['cid']}")->limit(8)->all();
				//获取栏目下商品数量
				foreach($topCate[$k]['second'][$key]['three'] as $tk =>$tv){
					$nums = count(M("goods")->where("category_cid='{$tv['cid']}'")->all());
					$topCate[$k]['second'][$key]['three'][$tk]['count'] =$nums;
				}
			}
		}		
		$this->assign('topCate',$topCate);
	}
	
	//页面头部网站导航
	public function nav(){
		//生活助手
		$server = M('category')->where("pid in(22,23,24,25,26,27)")->limit(14)->all();
		$this->assign('server',$server);
		//特色购物
		$hotcate =  M('category')->where("pid in(35,36,37,38)")->limit(10)->all();
		$this->assign('hotcate',$hotcate);
		//主题频道
		$them =  M('category')->where("pid in(43,44,45,46)")->limit(11)->all();
		$this->assign('them',$them);
		//更多热点
		$hot =  M('category')->where("pid in(51,52,53,54)")->limit(13)->all();
		$this->assign('hot',$hot);
	}
}
